/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-06-10     liuduanfei   first version
 */
 
#include <rtthread.h>
#include <rtdevice.h>

#define DBG_TAG "wdg"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

static struct rt_watchdog_device hc_wdg = {0};

static rt_err_t hc_wdg_init(rt_watchdog_t *wdt)
{
    LOG_D("hc_wdg_init");
    
    return RT_EOK;
}

static rt_err_t hc_wdg_control(rt_watchdog_t *wdt, int cmd, void *arg)
{
    LOG_D("hc_wdg_control");
    switch(cmd)
    {
    case RT_DEVICE_CTRL_WDT_GET_TIMEOUT:
        break;
    case RT_DEVICE_CTRL_WDT_SET_TIMEOUT:
        break;
    case RT_DEVICE_CTRL_WDT_GET_TIMELEFT:
        break;
    case RT_DEVICE_CTRL_WDT_KEEPALIVE:
        break;
    case RT_DEVICE_CTRL_WDT_START:
        break;
    case RT_DEVICE_CTRL_WDT_STOP:
        break;
    default:
        break;
    }
    return RT_EOK;
}

struct rt_watchdog_ops hc_wdg_ops = 
{
    hc_wdg_init,
    hc_wdg_control
};

int rt_hw_wdg_init(void)   
{
    rt_err_t ret;
    
    hc_wdg.ops = &hc_wdg_ops;

    ret = rt_hw_watchdog_register(&hc_wdg, "wdg", RT_DEVICE_FLAG_RDWR, RT_NULL);
    if (ret != RT_EOK)
    {
        LOG_E("can not register wdg device!");
        return -RT_EIO;
    }
    LOG_D("wdt device register success.");
    return RT_EOK;
}
INIT_BOARD_EXPORT(rt_hw_wdg_init);
